def convert2cmyk(img: list):
	# prepare the generated img
	out_img: list = []
	
	for row in img:
		new_row = []
		for pix in row:
			new_row.append(rgb2cmyk(pix[0], pix[1], pix[2]))
		out_img.append(new_row)
	
	return out_img

def rgb2cmyk(r, g, b):
	# 1. normalization
	r_nor = r / 255.0
	g_nor = g / 255.0
	b_nor = b / 255.0
	
	# 2. calculate CMYK
	C = 1 - r_nor
	M = 1 - g_nor
	Y = 1 - b_nor
	K = min(C, M, Y)
	
	# 3. yield the returning CMYK
	if K == 1:  # avoid divided by zero
		C = 0
		M = 0
		Y = 0
	else:
		C = (C - K) / (1 - K)
		M = (M - K) / (1 - K)
		Y = (Y - K) / (1 - K)
	
	# 4. return hundred percentage
	C = round(C * 100)
	M = round(M * 100)
	Y = round(Y * 100)
	K = round(K * 100)
	
	return [C, M, Y, K]
